const http = require('http');
const fs = require('fs')
const data = require('./user.json')

http.createServer((req, res) => {

  var url = req.url;
  if (url === '/') {
    url = '/index.html'
  }

  if (url.indexOf('favicon.ico') > -1) {
    res.end('')
  }

  var fullpath = __dirname + url;

  console.log(url);

  switch (url) {
    case "/index.html":
      res.setHeader('Content-Type', 'text/html');
      break;
    case "/logo.png":
      res.setHeader('Content-Type', 'image/png');
      break;
    case "/index.js":
      res.setHeader('Content-Type', 'application/x-javascript');
      break;
    case "/api/getlist":
      res.setHeader('Content-Type', 'application/json;chartset=utf-8;')
      res.write(JSON.stringify(data))
      res.end()
      break;

  }
  let result = fs.readFileSync(fullpath)
  res.write(result);
  res.end()



})
  .listen(3000, function () {
    console.log('localhost 3000 start...')
  })